<?php
namespace app\mall_back\model;

use think\admin\Model;

class TescoRecordModel extends Model{

    protected $table = 'one_tesco_record';

    public function user()
    {
        return $this->belongsTo('app\data\model\DataUser', 'u_id', 'id', [], 'LEFT')
            ->field('id,phone,headimg,nickname');
    }

    public function goods()
    {
        return $this->belongsTo('app\mall_back\model\GoodsModel', 'goods_id', 'id', [], 'LEFT')
            ->field('id,goods_name,cover');
    }

    public function goodsluckydraw()
    {
        return $this->belongsTo('app\mall_back\model\GoodsLuckyDrawModel', 'goods_lucky_draw_id', 'id', [], 'LEFT')
            ->field('id,unit_price,award_number, people_number,participants_number,residue_number,IFNULL(win_time,"") AS win_time, IFNULL(winning_user_id,0) AS winning_user_id,goods_id');
    }

    public function getLuckyNumbersAttr($value,$data){
        $goods_lucky_draw_id = $data['goods_lucky_draw_id'];
        return self::where(['goods_lucky_draw_id'=>$goods_lucky_draw_id,'u_id'=>$data['u_id']])->column('lucky_number');
    }

}